package com.ruoyi.edh.service.impl;

import java.util.List;

import com.ruoyi.common.enums.BillType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.edh.mapper.EdhBillMapper;
import com.ruoyi.edh.domain.EdhBill;
import com.ruoyi.edh.service.IEdhBillService;

/**
 * 易订货-账单Service业务层处理
 * 
 * @author xxx
 * @date 2020-09-07
 */
@Service
public class EdhBillServiceImpl implements IEdhBillService 
{
    @Autowired
    private EdhBillMapper edhBillMapper;

    /**
     * 查询易订货-账单
     * 
     * @param id 易订货-账单ID
     * @return 易订货-账单
     */
    @Override
    public EdhBill selectEdhBillById(Long id)
    {
        return edhBillMapper.selectEdhBillById(id);
    }

    /**
     * 查询易订货-账单列表
     * 
     * @param edhBill 易订货-账单
     * @return 易订货-账单
     */
    @Override
    public List<EdhBill> selectEdhBillList(EdhBill edhBill)
    {
        return edhBillMapper.selectEdhBillList(edhBill);
    }
   /**
     * 查询本人的账单列表
     *
     * @param edhBill 易订货-账单
     * @return 易订货-账单
     */
    @Override
    public List<EdhBill> mineList(EdhBill edhBill)
    {
        Long userId = SecurityUtils.getUserId();
        edhBill.setCreateBy(userId);
        return edhBillMapper.selectEdhBillList(edhBill);
    }

    /**
     * 新增易订货-账单
     * 
     * @param edhBill 易订货-账单
     * @return 结果
     */
    @Override
    public int insertEdhBill(EdhBill edhBill, BillType type, BillType priceSuffix)
    {
        edhBill.setName(type.getValue() +edhBill.getName());
        edhBill.setPrice(priceSuffix.getValue() + edhBill.getPrice());
        edhBill.setCreateTime(DateUtils.getNowDate());
        return edhBillMapper.insertEdhBill(edhBill);
    }

    /**
     * 修改易订货-账单
     * 
     * @param edhBill 易订货-账单
     * @return 结果
     */
    @Override
    public int updateEdhBill(EdhBill edhBill)
    {
        edhBill.setUpdateTime(DateUtils.getNowDate());
        return edhBillMapper.updateEdhBill(edhBill);
    }

    /**
     * 批量删除易订货-账单
     * 
     * @param ids 需要删除的易订货-账单ID
     * @return 结果
     */
    @Override
    public int deleteEdhBillByIds(Long[] ids)
    {
        return edhBillMapper.deleteEdhBillByIds(ids);
    }

    /**
     * 删除易订货-账单信息
     * 
     * @param id 易订货-账单ID
     * @return 结果
     */
    @Override
    public int deleteEdhBillById(Long id)
    {
        return edhBillMapper.deleteEdhBillById(id);
    }
}
